<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>x11-hash-js Browser-test</title>
</head>
<p><b>x11-hash Browser-test</b></p>

<script src="../node_modules/benchmark/node_modules/lodash/lodash.js"></script>
<script src="../node_modules/benchmark/node_modules/platform/platform.js"></script>
<script src="../node_modules/benchmark/benchmark.js"></script>

<script src="../dist/x11-hash.js"></script>
<script>
    // TODO: replace with Mocha
    var x11 = require('x11hash');
    var fox = 'The quick brown fox jumps over the lazy dog';
    var empty = '';
    var dash = 'DASH';
    var longDream = 'Take this kiss upon the brow! And, in parting from you now, Thus much let me avow-- You are not wrong, who deem That my days have been a dream; Yet if hope has flown away In a night, or in a day, In a vision, or in none, Is it therefore the less gone? All that we see or seem Is but a dream within a dream. I stand amid the roar Of a surf-tormented shore, And I hold within my hand Grains of the golden sand-- How few! yet how they creep Through my fingers to the deep, While I weep--while I weep! O God! can I not grasp Them with a tighter clasp? O God! can I not save One from the pitiless wave? Is all that we see or seem But a dream within a dream?';
    var int32 = [-1245000620, -1578223460, 654805539, -1068884769, -968029107, -8582190, 491541657, 290156804, 1046922525, 1254877013, -1307320917, 1691597203, 55068107, 1715389297, 252729336, 127805489];

    var result = ('empty string = ' + (x11.digest(empty) === "51b572209083576ea221c27e62b4e22063257571ccb6cc3dc3cd17eb67584eba" ? 'Pass' : 'Fail'));
    result += '<br>' + ('fox string = ' + (x11.digest(fox) === "534536a4e4f16b32447f02f77200449dc2f23b532e3d9878fe111c9de666bc5c" ? 'Pass' : 'Fail'));
    result += '<br>' + ('dash string = ' + (x11.digest(dash) === "fe809ebca8753d907f6ad32cdcf8e5c4e090d7bece5df35b2147e10b88c12d26" ? 'Pass' : 'Fail'));
    result += '<br>' + ('dream string = ' + (x11.digest(longDream) === "5c0996b9d49dbe84e29f1b818c1fa9e73549f894a71b8a258964b8f0ecf3c866" ? 'Pass' : 'Fail'));
    result += '<br>' + ('int32 = ' + (x11.digest(int32,2) === "ce06ca169b75084cd7b245966296e637e9af85091e848937af070f110cdb6298" ? 'Pass' : 'Fail'));
    result += '<br><hr>Benchmark running in console...';
    document.write(result);

    var sentence = longDream;
    var suite = new Benchmark.Suite;
    suite
            .add('Hash#blake', function() {
                x11.blake(sentence);
            })
            .add('Hash#bmw', function() {
                x11.bmw(sentence);
            })
            .add('Hash#cubehash', function() {
                x11.cubehash(sentence);
            })
            .add('Hash#echo', function() {
                x11.echo(sentence);
            })
            .add('Hash#groestl', function() {
                x11.groestl(sentence);
            })
            .add('Hash#jh', function() {
                x11.jh(sentence);
            })
            .add('Hash#keccak', function() {
                x11.keccak(sentence);
            })
            .add('Hash#luffa', function() {
                x11.luffa(sentence);
            })
            .add('Hash#shavite', function() {
                x11.shavite(sentence);
            })
            .add('Hash#simd', function() {
                x11.simd(sentence);
            })
            .add('Hash#skein', function() {
                x11.skein(sentence);
            })
            .add('Hash#x11', function() {
                x11.digest(sentence);
            })
//add listeners
            .on('cycle', function(event) {
                result = '<br><hr><br> Bench:' + String(event.target)
                console.log(String(event.target));
            })
            .on('complete', function() {
                console.log('Fastest is ' + this.filter('fastest').map('name'));
            })
// run async
            .run({ 'async': true });
</script>
</body>
</html>
